package br.unb.statistic.distribution;

import java.util.HashMap;

import br.unb.statistic.InterPacketTimeGenerator;
import br.unb.statistic.RandomGenerator;

public abstract class PacketsPerIntervalGenerator implements RandomGenerator,
        InterPacketTimeGenerator {

    protected double interval;
    private int remains;
    private double nextVal;

    public abstract double rand();

    public abstract void setParameters(HashMap parameters);

    public double nextInterPacketTime() {
        if (remains <= 0) {
            remains = (int) rand();
            if (remains <= 0) {
                double temp = this.interval;
                temp += this.nextInterPacketTime();
                return temp;
            } else if (remains != Double.NaN) {
                nextVal = this.interval / remains;
            } else {
                return Double.NaN;
            }
        }
        remains--;
        return nextVal;
    }
}
